﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Wicresoft.UnifyShow.Business;
using Microsoft.Practices.Unity;
using System.Windows.Forms.DataVisualization.Charting;
using System.IO;
using System.Drawing;
using Wicresoft.UnifyShow.Portal.Extensions;

namespace Wicresoft.UnifyShow.Portal.Controllers
{
    public class ProblemController : BaseController
    {
        private IProblem iproblem;

        protected override void Dispose(bool disposing)
        {
            ((IDisposable)iproblem).Dispose();
        }

        [InjectionConstructor]
        public ProblemController(IProblem e)
        {
            iproblem = e;
        }

        //已确定根本原因的问题数量/百分比
        [OutputCache(CacheProfile = "Report", VaryByParam = "sid;bnid;sTime;eTime")]
        public ActionResult PrimaryCauseProblem(int? sid, int? bnid, string sTime, string eTime)
        {
            DateTime sfTime = Convert.ToDateTime(sTime);
            DateTime efTime = Convert.ToDateTime(eTime);
            decimal allchcount = iproblem.GetClosedAndCompleteProblemCountBySiteAndBusiness(sid, bnid, sfTime, efTime);
            decimal reasonchcount = iproblem.GetReasonProblemCountBySiteAndBusiness(sid, bnid, sfTime, efTime);

            double chEscalation = (double)reasonchcount / (double)allchcount;
            double chOther = 1 - chEscalation;
            Chart chart = new Chart();
            chart.Width = GlobalHelper.Width;
            chart.Height = GlobalHelper.Height;

            double[] yval = { chEscalation, chOther };
            string[] xval = { (chEscalation * 100).ToString("0.00") + "%", (chOther * 100).ToString("0.00") + "%" };

            Series series = new Series();
            series.ChartType = SeriesChartType.Pie;

            series.Points.DataBindXY(xval, yval);

            series.Points[0].LegendText = "确定根本原因";
            series.Points[1].LegendText = "未确定根本原因";

            Legend l = new Legend();
            l.BorderColor = Color.Black;
            ChartArea chartArea = new ChartArea();
            chartArea.AxisY.LabelStyle.Format = "0%";
            //Title t = new Title("已确定根本原因的问题数量");
            //t.Font = GlobalHelper.fontTitle;

            chart.Legends.Add(l);
            //chart.Titles.Add(t);
            chart.Series.Add(series);
            chart.ChartAreas.Add(chartArea);
            //--chart样式--
            chart.Legends[0].Font = GlobalHelper.fontLegend;
            //chart1.Legends[0].FontColorCombo = Color.Red;
            //设置图颜色
            //chart1.Palette = ChartColorPalette.Pastel;
            //此属性设置为None才可以自定义调色板
            chart.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.None;
            // 自定义调色板
            Color[] colorSet = GlobalHelper.TwoSetPei;
            chart.PaletteCustomColors = colorSet;
            //图样式 concave/SoftEdge
            series["PieDrawingStyle"] = "SoftEdge";
            //分割饼图
            //series.Points[0]["Exploded"] = "true";
            // 设置标签风格
            series["PieLabelStyle"] = "Inside";
            return new ChartResult(chart);
        }

        //问题总数
        [OutputCache(CacheProfile = "Report", VaryByParam = "sid;bnid;sTime;eTime")]
        public ActionResult ProblemCount(int? sid, int? bnid, string sTime, string eTime)
        {
            //数据处理
            DateTime sfTime = DateTime.Parse(sTime.ToString().Trim());
            int year1 = Convert.ToInt16(sfTime.ToString("yyyy"));
            int month1 = Convert.ToInt16(sfTime.ToString("MM"));
            int day1 = Convert.ToInt16(sfTime.ToString("dd"));
            DateTime efTime = DateTime.Parse(eTime.ToString().Trim());
            int year2 = Convert.ToInt16(efTime.ToString("yyyy"));
            int month2 = Convert.ToInt16(efTime.ToString("MM"));
            int day2 = Convert.ToInt16(efTime.ToString("dd"));

            List<IncidentAndChangeModel> pms = iproblem.GetProblemCountGroupTimeBySiteAndBusiness(sid, bnid, sfTime, efTime);
            Series series1 = new Series();
            Chart colChart = new Chart();
            ChartArea chartArea1 = new ChartArea();
            //var group = pms.GroupBy(b => b.sign);
            //foreach (var k in group)
            //{
            //    series1.Points.AddXY(k.Key.ToString().Substring(k.Key.ToString().Length - 2), k.Average(b => b.alls));
            //}
            for (DateTime dt = new DateTime(year1, month1, day1); dt < new DateTime(year2, month2, day2); dt = dt.AddMonths(1))
            {
                //截取年月
                string mo = dt.Year.ToString() + dt.Month.ToString();
                if (dt.Month.ToString().Length < 2)
                {
                    mo = dt.Year.ToString() + "0" + dt.Month.ToString();
                }
                string b = mo.Substring(0, 4);
                var item1 = pms.Where(p => p.sign == mo).FirstOrDefault();
                if (item1 != null)
                {
                    series1.Points.AddXY(mo.Substring(mo.Length - 2), item1.alls);
                }
                else
                {
                    series1.Points.AddXY(mo.Substring(mo.Length - 2), 0);
                }
            }

            //设置Y轴刻度间隔
            double max = 0;
            double min = 0;
            if (series1.Points.Count != 0)
            {
                max = Math.Floor(series1.Points.FindMaxByValue().YValues[0] * 1.1);
                min = Math.Floor(series1.Points.FindMinByValue().YValues[0] * 0.9);
            }
            double differ = (max - min) / 10.0;
            int intervalY = (int)Math.Floor(differ) + 1;
            chartArea1.AxisY.Maximum = max;
            chartArea1.AxisY.Minimum = min;
            chartArea1.AxisY.Interval = intervalY;
            chartArea1.AxisX.Title = "(单位/月)";
            //chartArea1.AxisY.Title = "(单位/个)";
            series1.BorderColor = System.Drawing.Color.FromArgb(180, 26, 59, 105);
            series1.IsValueShownAsLabel = true;
            series1.XValueType = ChartValueType.String;
            ////设置宽度
            series1["PointWidth"] = "0.6";
            series1["DrawingStyle"] = "Emboss";
            series1.Name = "个数";
            series1.ChartType = SeriesChartType.Column;
            series1.IsValueShownAsLabel = true;
            //设置墙的宽度为
            //chartArea1.Area3DStyle.WallWidth = 30;
            //设置XY轴刻度间隔
            chartArea1.AxisX.Interval = 1;
            //是否3D显示
            //chartArea1.Area3DStyle.Enable3D = true;
            //设置图列
            Legend x = new Legend("Legend1");
            x.BorderColor = Color.Black;
            colChart.Legends.Add(x);
            //--chart样式--
            colChart.Legends[0].Font = GlobalHelper.fontLegend;
            //设置图标题（上方显示）
            //Title t = new Title("问题总数");
            //t.Font = GlobalHelper.fontTitle;
            //colChart.Titles.Add(t);

            colChart.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.None;
            Color[] colorSet = GlobalHelper.OneSet;
            colChart.PaletteCustomColors = colorSet;
            //不显示网格线
            chartArea1.AxisX.MajorGrid.Enabled = chartArea1.AxisY.MajorGrid.Enabled = false;
            colChart.Size = new System.Drawing.Size(GlobalHelper.Width, GlobalHelper.Height);
            colChart.Series.Add(series1);
            colChart.ChartAreas.Add(chartArea1);
            return new ChartResult(colChart);
        }

        //事件升级问题数量/百分比
        [OutputCache(CacheProfile = "Report", VaryByParam = "sid;bnid;sTime;eTime")]
        public ActionResult EscalationProblem(int? sid, int? bnid, string sTime, string eTime)
        {
                Chart chart = new Chart();
                Series series1 = new Series();
                DateTime sfTime = Convert.ToDateTime(sTime);
                DateTime efTime = Convert.ToDateTime(eTime);
                List<IncidentAndChangeModel> icm = iproblem.GetEscalationProblemCountBySiteAndBusiness(sid, bnid, sfTime, efTime);
                if (icm.FirstOrDefault(p => p.ID == 1000) == null)
                {
                    icm.Add(new IncidentAndChangeModel { alls = 0, ID = 1000 });
                }
                if (icm.FirstOrDefault(p => p.ID == 2000) == null)
                {
                    icm.Add(new IncidentAndChangeModel { alls = 0, ID = 2000 });
                }
                if (icm.FirstOrDefault(p => p.ID == 3000) == null)
                {
                    icm.Add(new IncidentAndChangeModel { alls = 0, ID = 3000 });
                }

                double incidentNum = 0;
                double otherNum = 0;
                for (int i = 0; i < icm.Count(); i++)
                {
                    if (icm[i].ID == 1000)
                    {
                        incidentNum += Convert.ToDouble(icm[i].alls);
                    }
                    if (icm[i].ID == 2000)
                    {
                        otherNum += Convert.ToDouble(icm[i].alls);
                    }
                    if (icm[i].ID == 3000)
                    {
                        otherNum += Convert.ToDouble(icm[i].alls);
                    }
                }
                double incidentNums = Convert.ToDouble(incidentNum / (incidentNum + otherNum));
                double otherNums = Convert.ToDouble((otherNum / (incidentNum + otherNum)));
                double[] yval = { incidentNums, otherNums };
                string[] xval = { (incidentNums * 100).ToString("0.00") + "%", (otherNums * 100).ToString("0.00") + "%" };
                series1.Points.DataBindXY(xval, yval);
                series1.ChartType = SeriesChartType.Pie;
                series1.Points[0].LegendText = "事件升级";
                series1.Points[1].LegendText = "非事件升级";
                
                chart.Width = GlobalHelper.Width;
                chart.Height = GlobalHelper.Height;

                Legend l = new Legend();
                l.BorderColor = Color.Black;
                ChartArea chartArea = new ChartArea();
                chartArea.AxisY.LabelStyle.Format = "0%";
                //Title t = new Title("事件升级问题数量");
                //t.Font = GlobalHelper.fontTitle;

                chart.Legends.Add(l);
                //chart.Titles.Add(t);
                chart.Series.Add(series1);
                chart.ChartAreas.Add(chartArea);
                //--chart样式--
                chart.Legends[0].Font = GlobalHelper.fontLegend;
                //chart1.Legends[0].FontColorCombo = Color.Red;
                //设置图颜色
                //chart1.Palette = ChartColorPalette.Pastel;
                //此属性设置为None才可以自定义调色板
                chart.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.None;
                // 自定义调色板
                Color[] colorSet = GlobalHelper.SixColorSet;
                chart.PaletteCustomColors = colorSet;
                //图样式 concave/SoftEdge
                series1["PieDrawingStyle"] = "SoftEdge";
                //分割饼图
                //series.Points[0]["Exploded"] = "true";
                // 设置标签风格
                series1["PieLabelStyle"] = "Inside";
                return new ChartResult(chart);
        }

        //重大问题数量/百分比
        [OutputCache(CacheProfile = "Report", VaryByParam = "sid;bnid;sTime;eTime")]
        public ActionResult ImpactProblem(int? sid, int? bnid, string sTime, string eTime)
        {
            //数据处理
            DateTime sfdate = DateTime.Parse(sTime.ToString().Trim());
            int sfyear = Convert.ToInt16(sfdate.ToString("yyyy"));
            int sfmonth = Convert.ToInt16(sfdate.ToString("MM"));
            int sfday = Convert.ToInt16(sfdate.ToString("dd"));
            DateTime efdate = DateTime.Parse(eTime.ToString().Trim());
            int efyear = Convert.ToInt16(efdate.ToString("yyyy"));
            int efmonth = Convert.ToInt16(efdate.ToString("MM"));
            int efday = Convert.ToInt16(efdate.ToString("dd"));

            List<IncidentAndChangeModel> allchcount = iproblem.GetProblemCountGroupTimeBySiteAndBusiness(sid, bnid, sfdate, efdate);
            List<IncidentAndChangeModel> ims = iproblem.GetProblemImpactSortCountBySiteAndBusiness(sid, bnid, sfdate, efdate);

            Series series1 = new Series();
            Series series2 = new Series();
            Chart colChart = new Chart();
            ChartArea chartArea = new ChartArea();

            for (DateTime dt = new DateTime(sfyear, sfmonth, sfday); dt < new DateTime(efyear, efmonth, efday); dt = dt.AddMonths(1))
            {
                //截取年月
                string mo = dt.Year.ToString() + dt.Month.ToString();
                if (dt.Month.ToString().Length < 2)
                {
                    mo = dt.Year.ToString() + "0" + dt.Month.ToString();
                }
                string b = mo.Substring(0, 4);
                //严重
                var item = ims.Where(p => p.sign == mo).FirstOrDefault();
                var allitem = allchcount.Where(p => p.sign == mo).FirstOrDefault();
                //百分比
                if (allitem != null && item != null)
                {
                    Decimal g1 = Convert.ToDecimal(item.alls / allitem.alls);
                    series2.Points.AddXY(mo.Substring(mo.Length - 2), g1.ToString("0.00"));
                    series1.Points.AddXY(mo.Substring(mo.Length - 2), (1 - g1).ToString("0.00"));
                }
                else
                {
                    series2.Points.AddXY(mo.Substring(mo.Length - 2), 0);
                    series1.Points.AddXY(mo.Substring(mo.Length - 2), 0);
                }
            }
            chartArea.AxisX.Title = "(单位/月)";
            //chartArea1.AxisY.Title = "(单位/个)";
            chartArea.Name = "Default";
            chartArea.AxisY.LabelStyle.Format = "0%";
            //设置图标题（下方显示）
            //chartArea1.AxisX.Title = "事件影响程度";
            //是否3D显示
            chartArea.Area3DStyle.Enable3D = true;
            //设置图列
            Legend x = new Legend("Legend1");
            //x.BackColor = Color.White;
            x.BorderColor = Color.Black;
            //x.Title = "影响程度";
            colChart.Legends.Add(x);
            //--chart样式--
            colChart.Legends[0].Font = GlobalHelper.fontLegend;
            //设置图标题（上方显示）
            //Title t = new Title("重大问题数量");
            //t.Font = GlobalHelper.fontTitle;
            //colChart.Titles.Add(t);
            //设置XY轴刻度间隔
            chartArea.AxisY.Interval = 0.2;
            chartArea.AxisX.Interval = 1;
            //设置XY轴最大值
            chartArea.AxisY.Maximum = 1;
            //chartArea1.AxisX.Maximum = 12;
            //设置宽度
            series1["PointWidth"] = "0.5";
            series2["PointWidth"] = "0.5";
            //设置墙的宽度为
            chartArea.Area3DStyle.WallWidth = 2;
            //设置背景为白色
            chartArea.BackColor = Color.White;


            //series1.BorderColor = System.Drawing.Color.FromArgb(189, 26, 59, 115);
            //series1.ChartArea = "Default";
            //series1.Legend = "Default";
            series2.Name = "重大";
            series1.Name = "一般";
            //series1.XValueType = ChartValueType.String;
            series1.LabelFormat = "0%";
            series2.LabelFormat = "0%";
            series1.ChartType = SeriesChartType.StackedColumn;
            series2.ChartType = SeriesChartType.StackedColumn;
            series1.IsValueShownAsLabel = true;
            series2.IsValueShownAsLabel = true;

            colChart.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.None;
            Color[] colorSet = GlobalHelper.TwoSetBar;
            colChart.PaletteCustomColors = colorSet;

            colChart.Size = new System.Drawing.Size(GlobalHelper.Width, GlobalHelper.Height);
            colChart.Series.Add(series1);
            colChart.Series.Add(series2);
            colChart.ChartAreas.Add(chartArea);
            return new ChartResult(colChart);
        }

        //供应商解决的问题数量/百分比
        [OutputCache(CacheProfile = "Report", VaryByParam = "sid;bnid;sTime;eTime")]
        public ActionResult FirmProStatusProblem(int? sid, int? bnid, string sTime, string eTime)
        {
            DateTime sfTime = Convert.ToDateTime(sTime);
            DateTime efTime = Convert.ToDateTime(eTime);
            decimal allchcount = iproblem.GetClosedAndCompleteProblemCountBySiteAndBusiness(sid, bnid, sfTime, efTime);
            decimal firmchcount = iproblem.GetProblemFirmCountBySiteAndBusiness(sid, bnid, sfTime, efTime);

            double chEscalation = (double)firmchcount / (double)allchcount;
            double chOther = 1 - chEscalation;
            Chart chart = new Chart();
            chart.Width = GlobalHelper.Width;
            chart.Height = GlobalHelper.Height;

            double[] yval = { chEscalation, chOther };
            string[] xval = { (chEscalation * 100).ToString("0.00") + "%", (chOther * 100).ToString("0.00") + "%" };

            Series series = new Series();
            series.ChartType = SeriesChartType.Pie;

            series.Points.DataBindXY(xval, yval);

            series.Points[0].LegendText = "供应商解决";
            series.Points[1].LegendText = "非供应商解决";

            Legend l = new Legend();
            l.BorderColor = Color.Black;
            ChartArea chartArea = new ChartArea();
            chartArea.AxisY.LabelStyle.Format = "0%";
            //Title t = new Title("供应商解决的问题数量");
            //t.Font = GlobalHelper.fontTitle;

            chart.Legends.Add(l);
            //chart.Titles.Add(t);
            chart.Series.Add(series);
            chart.ChartAreas.Add(chartArea);
            //--chart样式--
            chart.Legends[0].Font = GlobalHelper.fontLegend;
            //chart1.Legends[0].FontColorCombo = Color.Red;
            //设置图颜色
            //chart1.Palette = ChartColorPalette.Pastel;
            //此属性设置为None才可以自定义调色板
            chart.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.None;
            // 自定义调色板
            Color[] colorSet = GlobalHelper.TwoSetPei;
            chart.PaletteCustomColors = colorSet;
            //图样式 concave/SoftEdge
            series["PieDrawingStyle"] = "SoftEdge";
            //分割饼图
            //series.Points[0]["Exploded"] = "true";
            // 设置标签风格
            series["PieLabelStyle"] = "Inside";
            return new ChartResult(chart);
        }

        //平均问题诊断时间
        [OutputCache(CacheProfile = "Report", VaryByParam = "sid;bnid;sTime;eTime")]
        public ActionResult AvgResolveTimeProblem(int? sid, int? bnid, string sTime, string eTime)
        {
            //数据处理
            DateTime date1 = DateTime.Parse(sTime.ToString().Trim());
            int year1 = Convert.ToInt16(date1.ToString("yyyy"));
            int month1 = Convert.ToInt16(date1.ToString("MM"));
            int day1 = Convert.ToInt16(date1.ToString("dd"));
            DateTime date2 = DateTime.Parse(eTime.ToString().Trim());
            int year2 = Convert.ToInt16(date2.ToString("yyyy"));
            int month2 = Convert.ToInt16(date2.ToString("MM"));
            int day2 = Convert.ToInt16(date2.ToString("dd"));
            //取数据
            List<IncidentAndChangeModel> ims = iproblem.GetAvgtimeProblemBySiteAndBusiness(sid, bnid, date1, date2);
            Series series1 = new Series();
            Chart colChart = new Chart();
            ChartArea chartArea1 = new ChartArea();
            for (DateTime dt = new DateTime(year1, month1, day1); dt < new DateTime(year2, month2, day2); dt = dt.AddMonths(1))
            {
                //截取年月
                string mo = dt.Year.ToString() + dt.Month.ToString();
                if (dt.Month.ToString().Length < 2)
                {
                    mo = dt.Year.ToString() + "0" + dt.Month.ToString();
                }
                string b = mo.Substring(0, 4);
                var item1 = ims.Where(p => p.sign == mo).FirstOrDefault();
                if (item1 != null)
                {
                    series1.Points.AddXY(mo.Substring(mo.Length - 2), item1.alls.ToString("0.00"));
                }
                else
                {
                    series1.Points.AddXY(mo.Substring(mo.Length - 2), 0);
                }
            }

            //设置Y轴刻度间隔
            double max = 0;
            double min = 0;
            if (series1.Points.Count != 0)
            {
                max = series1.Points.FindMaxByValue().YValues[0] * 1.5;
                min = series1.Points.FindMinByValue().YValues[0] * 1.2;
            }
            double differ = (max - min) / 10.0;
            int intervalY = (int)Math.Floor(differ);
            //double intervalY = differ;
            chartArea1.AxisY.Maximum = max;
            chartArea1.AxisY.Minimum = min;
            chartArea1.AxisY.Interval = intervalY;
            chartArea1.AxisX.Title = "(单位/月)";
            //chartArea1.AxisY.Title = "(单位/个)";
            series1.BorderColor = System.Drawing.Color.FromArgb(180, 26, 59, 105);
            series1.IsValueShownAsLabel = true;
            series1.XValueType = ChartValueType.String;
            ////设置宽度
            series1["PointWidth"] = "0.6";
            series1["DrawingStyle"] = "Emboss";
            series1.Name = "小时";
            series1.ChartType = SeriesChartType.Column;
            series1.IsValueShownAsLabel = true;
            //设置墙的宽度为
            //chartArea1.Area3DStyle.WallWidth = 30;
            //设置XY轴刻度间隔
            chartArea1.AxisX.Interval = 1;
            //是否3D显示
            //chartArea1.Area3DStyle.Enable3D = true;
            //不显示网格线
            chartArea1.AxisX.MajorGrid.Enabled = chartArea1.AxisY.MajorGrid.Enabled = false;
            //设置图列
            Legend x = new Legend("Legend1");
            x.BorderColor = Color.Black;
            colChart.Legends.Add(x);
            //--chart样式--
            colChart.Legends[0].Font = GlobalHelper.fontLegend;
            //设置图标题（上方显示）
            //Title t = new Title("平均问题诊断时间");
            //t.Font = GlobalHelper.fontTitle;
            //colChart.Titles.Add(t);

            colChart.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.None;
            Color[] colorSet = GlobalHelper.OneSet;
            colChart.PaletteCustomColors = colorSet;
            colChart.Size = new System.Drawing.Size(GlobalHelper.Width, GlobalHelper.Height);
            colChart.Series.Add(series1);
            colChart.ChartAreas.Add(chartArea1);
            return new ChartResult(colChart);
        }

        //关闭问题数量/百分比
        [OutputCache(CacheProfile = "Report", VaryByParam = "sid;bnid;sTime;eTime")]
        public ActionResult ClosedProblem(int? sid, int? bnid, string sTime, string eTime)
        {
            DateTime sfTime = Convert.ToDateTime(sTime);
            DateTime efTime = Convert.ToDateTime(eTime);
            decimal allchcount = iproblem.GetProblemCountBySiteAndBusiness(sid, bnid, sfTime, efTime);
            decimal closecount = iproblem.GetClosedProblemCountBySiteAndBusiness(sid, bnid, sfTime, efTime);

            double chClosed = (double)closecount / (double)allchcount;
            double chOther = 1 - chClosed;
            Chart chart = new Chart();
            chart.Width = GlobalHelper.Width;
            chart.Height = GlobalHelper.Height;

            double[] yval = { chClosed, chOther };
            string[] xval = { (chClosed * 100).ToString("0.00") + "%", (chOther * 100).ToString("0.00") + "%" };

            Series series = new Series();
            series.ChartType = SeriesChartType.Pie;

            series.Points.DataBindXY(xval, yval);

            series.Points[0].LegendText = "已关闭";
            series.Points[1].LegendText = "未关闭 ";

            Legend l = new Legend();
            l.BorderColor = Color.Black;
            ChartArea chartArea = new ChartArea();
            chartArea.AxisY.LabelStyle.Format = "0%";
            //Title t = new Title("已关闭问题数量");
            //t.Font = GlobalHelper.fontTitle;

            chart.Legends.Add(l);
            //chart.Titles.Add(t);
            chart.Series.Add(series);
            chart.ChartAreas.Add(chartArea);
            //--chart样式--
            chart.Legends[0].Font = GlobalHelper.fontLegend;
            //chart1.Legends[0].FontColorCombo = Color.Red;
            //设置图颜色
            //chart1.Palette = ChartColorPalette.Pastel;
            //此属性设置为None才可以自定义调色板
            chart.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.None;
            // 自定义调色板
            Color[] colorSet = GlobalHelper.TwoSetPei;
            chart.PaletteCustomColors = colorSet;
            //图样式 concave/SoftEdge
            series["PieDrawingStyle"] = "SoftEdge";
            //分割饼图
            //series.Points[0]["Exploded"] = "true";
            // 设置标签风格
            series["PieLabelStyle"] = "Inside";
            return new ChartResult(chart);
        }

        //根本解决的问题数量和百分比
        [OutputCache(CacheProfile = "Report", VaryByParam = "sid;bnid;sTime;eTime")]
        public ActionResult SolveProblem(int? sid, int? bnid, string sTime, string eTime)
        {
            DateTime sfTime = Convert.ToDateTime(sTime);
            DateTime efTime = Convert.ToDateTime(eTime);
            decimal allchcount = iproblem.GetClosedAndCompleteProblemCountBySiteAndBusiness(sid, bnid, sfTime, efTime);
            decimal solvechcount = iproblem.GetSolveProblemCountBySiteAndBusiness(sid, bnid, sfTime, efTime);

            double chEscalation = (double)solvechcount / (double)allchcount;
            double chOther = 1 - chEscalation;
            Chart chart = new Chart();
            chart.Width = GlobalHelper.Width;
            chart.Height = GlobalHelper.Height;

            double[] yval = { chEscalation, chOther };
            string[] xval = { (chEscalation * 100).ToString("0.00") + "%", (chOther * 100).ToString("0.00") + "%" };

            Series series = new Series();
            series.ChartType = SeriesChartType.Pie;

            series.Points.DataBindXY(xval, yval);

            series.Points[0].LegendText = "根本解决的问题";
            series.Points[1].LegendText = "非根本解决的问题";

            Legend l = new Legend();
            l.BorderColor = Color.Black;
            ChartArea chartArea = new ChartArea();
            chartArea.AxisY.LabelStyle.Format = "0%";
            //Title t = new Title("根本解决的问题数量");
            //t.Font = GlobalHelper.fontTitle;

            chart.Legends.Add(l);
            //chart.Titles.Add(t);
            chart.Series.Add(series);
            chart.ChartAreas.Add(chartArea);
            //--chart样式--
            chart.Legends[0].Font = GlobalHelper.fontLegend;
            //chart1.Legends[0].FontColorCombo = Color.Red;
            //设置图颜色
            //chart1.Palette = ChartColorPalette.Pastel;
            //此属性设置为None才可以自定义调色板
            chart.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.None;
            // 自定义调色板
            Color[] colorSet = GlobalHelper.TwoSetPei;
            chart.PaletteCustomColors = colorSet;
            //图样式 concave/SoftEdge
            series["PieDrawingStyle"] = "SoftEdge";
            //分割饼图
            //series.Points[0]["Exploded"] = "true";
            // 设置标签风格
            series["PieLabelStyle"] = "Inside";
            return new ChartResult(chart);
        }

        ////超时问题数量/百分比
        //[OutputCache(CacheProfile = "Report", VaryByParam = "sid;bnid;sTime;eTime")]
        //public ActionResult TimeOutProblem(int? sid, int? bnid, string sTime, string eTime)
        //{
        //    DateTime sfTime = Convert.ToDateTime(sTime);
        //    DateTime efTime = Convert.ToDateTime(eTime);
        //    decimal allchcount = iproblem.GetClosedAndCompleteProblemCountBySiteAndBusiness(sid, bnid, sfTime, efTime);
        //    decimal timeoutchcount = iproblem.GetProblemTimeOutCountBySiteAndBusiness(sid, bnid, sfTime, efTime);

        //    double chEscalation = (double)timeoutchcount / (double)allchcount;
        //    double chOther = 1 - chEscalation;
        //    Chart chart = new Chart();
        //    chart.Width = GlobalHelper.Width;
        //    chart.Height = GlobalHelper.Height;

        //    double[] yval = { chEscalation, chOther };
        //    string[] xval = { (chEscalation * 100).ToString("0.00") + "%", (chOther * 100).ToString("0.00") + "%" };

        //    Series series = new Series();
        //    series.ChartType = SeriesChartType.Pie;

        //    series.Points.DataBindXY(xval, yval);

        //    series.Points[0].LegendText = "超时问题";
        //    series.Points[1].LegendText = "未超时问题";

        //    Legend l = new Legend();
        //    l.BorderColor = Color.Black;
        //    ChartArea chartArea = new ChartArea();
        //    chartArea.AxisY.LabelStyle.Format = "0%";
        //    //Title t = new Title("超时问题数量");
        //    //t.Font = GlobalHelper.fontTitle;

        //    chart.Legends.Add(l);
        //    //chart.Titles.Add(t);
        //    chart.Series.Add(series);
        //    chart.ChartAreas.Add(chartArea);
        //    //--chart样式--
        //    chart.Legends[0].Font = GlobalHelper.fontLegend;
        //    //chart1.Legends[0].FontColorCombo = Color.Red;
        //    //设置图颜色
        //    //chart1.Palette = ChartColorPalette.Pastel;
        //    //此属性设置为None才可以自定义调色板
        //    chart.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.None;
        //    // 自定义调色板
        //    Color[] colorSet = GlobalHelper.TwoSetPei;
        //    chart.PaletteCustomColors = colorSet;
        //    //图样式 concave/SoftEdge
        //    series["PieDrawingStyle"] = "SoftEdge";
        //    //分割饼图
        //    //series.Points[0]["Exploded"] = "true";
        //    // 设置标签风格
        //    series["PieLabelStyle"] = "Inside";
        //    return new ChartResult(chart);
        //}

    }
}
